// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Router from 'vue-router'
import App from './App'
import router from './router'
import vshare from 'vshare'
import store from './store/store'
import fetch from './util/fetch'
import Storage from '@/util/StorageUtil'
// import api from './util/APIUtil'
import vueQr from "vue-qr"
// 引入vant
import vant from 'vant'
import 'vant/lib/index.css';

Vue.component('vueQr', vueQr)


const extend = Vue.prototype
Vue.prototype.Sto = Storage
Vue.config.productionTip = false
Vue.use(Router)
Vue.use(vshare)
Vue.use(vant)
extend.$post = fetch.post
extend.$get = fetch.get
extend.$form = fetch.upload
// extend.$api = api


Vue.prototype.url = "http://139.198.178.82:9090/Shopping/api/v1/"
Vue.prototype.imgurl = "http://139.198.178.82:9090/Shopping"
Vue.prototype.url2 = "/api"
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  // if (to.name !== 'Login' && !isAuthenticated && to.name != '/') next({ name: '/Login' })
  // // 如果用户未能验证身份，则 `next` 会被调用两次
  // next()
  let user = sessionStorage.getItem("user")
  let path = ['/cart', '/user']
  if (!user) {
    path.forEach(e => {
      if (to.path == e) {
        Vue.prototype.$dialog({ message: "你还没有登录请先登录" })
        next("/Login")
      }
    });
  }
  next()
})